package com.corx.network.core.holder;

import com.corx.network.core.manager.DeviceStateManager;

/**
 * @author gx
 * @version 1.0.0
 */
public class DeviceStateManagerHolder {

    private static volatile DeviceStateManager instance;

    public static void register(DeviceStateManager manager) {
        if (instance != null) {
            throw new IllegalStateException("DeviceStateManager 已经注册！");
        }
        if (manager == null) {
            throw new IllegalStateException("register DeviceStateManager 不能为空！");
        }
        instance = manager;
    }


    public static DeviceStateManager get() {
        if (instance == null) {
            throw new IllegalStateException("DeviceStateManager 尚未初始化！");
        }
        return instance;
    }

    public static synchronized void reset() {
        if (instance != null) {
            try {
                instance.destroy();
            } finally {
                instance = null;
            }
        }
    }

    public static boolean isRegistered() {
        return instance != null;
    }


}
